﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using CoreEx.Common.Linq;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Linq.Implementation
{
    //[Implements(typeof(IExpressionRewriter), ServiceName = "ConvertRewriter")]
    public class ConvertRewriter : ExpressionVisitor, IExpressionRewriter
    {
        protected override System.Linq.Expressions.Expression VisitUnary(UnaryExpression u)
        {
            if (u.NodeType == ExpressionType.Convert || u.NodeType == ExpressionType.Quote)
                return Visit(u.Operand);
            return base.VisitUnary(u);
        }

        public Expression Rewrite(Expression expression)
        {
            return Visit(expression);
        }
    }
}
